package com.yoyo.svgdemo.activities;/**
 * Created by liumin on 2015-9-1.
 */


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yoyo.svgdemo.R;
import com.yoyo.svgdemo.fragment.FragmentSVG1;
import com.yoyo.svgdemo.fragment.FragmentSVG2;
import com.yoyo.svgdemo.fragment.FragmentSVG3;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: Missa
 * Date: 2015-09-01
 * Time: 11:14
 * Description:
 */
public class ItemActivity extends AppCompatActivity {

    private ViewPager mViewPager;
    private int mPosition;
    private Map<Integer, Fragment> mFragmentMap;
    private Context ctx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ctx = this;
        System.out.println("onCreate =====================");
        System.out.println("onCreate =====================");
        setContentView(R.layout.activity_item);

        mViewPager = ((ViewPager) findViewById(R.id.viewPager));
        Toolbar toolbar = (Toolbar) findViewById(R.id.appBar);
        setSupportActionBar(toolbar);

        mPosition = getIntent().getIntExtra(MainActivity.ITEM_POSITION, 0);
        mFragmentMap = (Map<Integer, Fragment>) getIntent().getSerializableExtra(MainActivity.FRAGMENT_MAP);

        mViewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
        mViewPager.setCurrentItem(mPosition);
//        mViewPager.setOffscreenPageLimit(3);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        System.out.println("onNewIntent =======================");

    }

    class ViewPagerAdapter extends FragmentStatePagerAdapter {

        public ViewPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentMap.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentMap.size();
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
//            super.destroyItem(container, position, object);
        }
    }
}
